from flask import Flask
from flask_jsonrpc import JSONRPC

from registry import RegistryProvider, provider_address

INTERFACE = 'com.flask.demo.Hi'
PORT = 8000
ZOO_ADDRESS = "127.0.0.1:2181"

registry_provider = RegistryProvider(ZOO_ADDRESS, "MyApp", provider_address(ZOO_ADDRESS), PORT)
registry_provider.registry(INTERFACE, "hi")

app = Flask(__name__)
jsonrpc = JSONRPC(app, '/dubbo/' + INTERFACE, enable_web_browsable_api=True)


@jsonrpc.method('App.index')
def hi(name: str) -> str:
    return "Hi %s" % name


if __name__ == "__main__":
    app.run(host='0.0.0.0', port=PORT)
